package com.qf.votesystem.controller;


import com.qf.votesystem.entity.service.IPhonenameService;
import com.qf.votesystem.vo.ResultVo;
import com.qf.votesystem.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.io.IOException;

@Component
@RequestMapping("/callback")
public class WebSocketController {

    @Autowired
    IPhonenameService phonenameService;

    @Scheduled(cron = "0/3 * * * * ?")
    @GetMapping("/count")
    public void callback() throws IOException {


        long count = phonenameService.count();

        String num = String.valueOf(count);

        WebSocketServer.sendMsg(num);

    }


}
